package com.controller;

import java.io.IOException;
import java.io.PrintWriter;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

@WebServlet("/User")
public class UserController extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		this.doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
			req.setCharacterEncoding("utf-8");
			resp.setContentType("text/html;charset=utf-8");
			String name = req.getParameter("username");
			String age = req.getParameter("age");
			String sex = req.getParameter("sex");
			String f[]	= req.getParameterValues("friend");
			String s="";
			for(int i = 0; i<f.length; i++) {
				s += f[i]+"&nbsp;&nbsp;";
			}
			String city = req.getParameter("city");
			PrintWriter out = resp.getWriter();
			out.println("<html><body><h1>用户信息</h1>");
			out.println("<h2>姓名:"+name+"</h2><h2>年龄:"+age+"</h2>");
			out.println("<h2>性别:"+sex+"</h2><h2>好友:"+s+"</h2>");
			out.println("<h2>城市:"+city+"</h2></body></html>");
			
	}
		
}
